<?php
class Preader {
	private $documentobj; //this is only body object
	private $holeboj; //this is the hole html object
	private $regs = array (
		"unlikelyCandidatesRe" => "/combx|comment|disqus|foot|header|menu|meta|nav|rss|shoutbox|sidebar|sponsor/i",
		"okMaybeItsACandidateRe" => "/and|article|body|column|main/i",
		"positiveRe" => "/article|body|content|entry|hentry|page|pagination|post|text/i",
		"negativeRe" => "/combx|comment|contact|foot|footer|footnote|link|media|meta|promo|related|scroll|shoutbox|sponsor|tags|widget/i",
		"divToPElementsRe" => "/<(a|blockquote|dl|div|img|ol|p|pre|table|ul)/i",
		"replaceBrsRe" => "/(<br[^>]*>[ \n\r\t]*){2,}/i",
		"replaceFontsRe" => "/<(\/?)font[^>]*>/i",
		"trimRe" => "/^\s+|\s+$/",
		"normalizeRe" => "/\s{2,}/",
		"killBreaksRe" => "/(<br\s*\/?>(\s|&nbsp;?)*){1,}/",
		"videoRe" => "/http:\/\/(www\.)?(youtube|vimeo)\.com/i",
		"annotationRe" => "/<!--.*?-->/i"
	);
	function __construct($documentobj, $holeobj) {
		$this->documentobj = $documentobj;
		$this->holeobj = $holeobj;
	}

	/**
	 * remove all the script tags
	 */
	public function removeScript() {
		$this->documentobj->find('script')->remove();
	}
	/**
	 * remove all the style tags
	 */
	public function removeStyle() {
		$this->documentobj->find('style')->remove();
	}
	/**
	 * prepare the html document for scrape it.
	 */
	public function prepDocument() {
		$html = preg_replace($this->regs['replaceBrsRe'], '</p><p>', $this->documentobj->html());
		$html = preg_replace($this->regs['replaceFontsRe'], '<$1span>', $html);
		$html = preg_replace($this->regs['annotationRe'], '', $html);
		$this->documentobj->html($html);
	}
	/**
	 * get the article title as an H1
	 */
	public function getArticlTitle() {
		$title = phpQuery :: newDocument('<h1></h1>');
		$title = $title['h1']->html(trim($this->holeobj->find('title')->html()));

		return $title;
	}
	/**
	 * grabArticle - Using a variety of metrics (content score,
	 * classname, element types), find the content that is most likely
	 * to be the stuff a user wants to read. Then return it wrapped up
	 * in a div.
	 */
	public function grabArticle() {
		$divs=$this->documentobj->find('div')->replace;
		
	}
	public function getHtml() {
		return $this->documentobj->htmlOuter();
	}
}
?>